package com.lids.test;

import org.jboss.marshalling.Marshaller;
import org.jboss.marshalling.MarshallerFactory;
import org.jboss.marshalling.Marshalling;
import org.jboss.marshalling.MarshallingConfiguration;
import org.jboss.marshalling.Unmarshaller;

import java.io.IOException;

/**
 * @Des
 * @Date: 2021/1/11 14:05
 */
public class MarshallingCodecFactory {

    /**
     *  创建Jboss Marshaller
     * @return
     * @throws Exception
     */
    protected static Marshaller buildMarshalling() throws IOException{
       final MarshallerFactory marshallerFactory = Marshalling
               .getProvidedMarshallerFactory("serial");
       final MarshallingConfiguration configuration = new MarshallingConfiguration();
       configuration.setVersion(5);
       Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
       return marshaller;
    }

    /**
     *  创建Jboss Unmarshaller
     * @return
     * @throws IOException
     */
    protected static Unmarshaller buildUnmarshaller() throws IOException{
      final MarshallerFactory marshallerFactory = Marshalling
              .getProvidedMarshallerFactory("serial");
      final MarshallingConfiguration configuration = new MarshallingConfiguration();
      configuration.setVersion(5);
      final Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
      return unmarshaller;
    }

}
